<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Đăng ký</title>
</head>

<body>
<?php
include("kn.php");
$hoten = $_POST["hoten"];
$phai = $_POST["phai"];
$diachi = $_POST["diachi"];
$ngaysinh = $_POST["nam"]."-".$_POST["thang"]."-".$_POST["ngay"];
$dienthoai = $_POST["dienthoai"];
$email = $_POST["email"];
$user = $_POST["user"];
$matkhau = $_POST["matkhau"];
$xacnhanmatkhau = $_POST["xacnhanmatkhau"];
$lenh = "select * from khachhang where user = '$user'";
$kq = mysql_query($lenh);
$n = mysql_num_rows($kq);
if($n > 0)
{
	
	?>
    <script>
	alert('tài khoản này đã có!');
	</script>
    
    <?php
	
}
else
{
if(isset($_POST["dk"]))
{
	$lenhthem = "insert into khachhang(tenkhachhang,phai,diachi,ngaysinh,dienthoai,email,user,matkhau,xacnhanmatkhau)values('$hoten','$phai','$diachi','$ngaysinh','$dienthoai','$email','$user','$matkhau','$xacnhanmatkhau')";
	$kqthem = mysql_query($lenhthem);
	
	


if($kqthem)
{
	?>
    <script>
	alert('Đăng ký thành công!');
	
	</script>
    
    <?php
	
}
else
{
	?>
     <script>
	alert('Đăng ký thất bại!');
	
	</script>
    <?php
	
}

}
}
?>
<form id="formdangky" name="formdangky" method="post" action="">
  <table width="550" border="1" align="center" cellpadding="0" cellspacing="0" style="border-collapse:collapse" bgcolor="#FFFF99" bordercolor="#FF99CC">
    <tr>
      <td height="35" colspan="2" align="center" bgcolor="#FFFF66"><strong>ĐĂNG KÝ THÀNH VIÊN</strong></td>
    </tr>
    <tr>
      <td width="180" style="padding-left:15px">Họ tên</td>
      <td width="364"><label for="hoten"></label>
      <input name="hoten" type="text" id="hoten" size="40" value="<?php  echo $_POST["hoten"];   ?>" /></td>
    </tr>
    <tr>
      <td style="padding-left:15px">Phái</td>
      <td>
      <?php
	  if($_GET["phai"] == 1)
      echo"<input type='radio' name='phai' id='nam' value='1' checked/>
      <label for='nam'>Nam 
        <input type='radio' name='phai' id='nu'value='0' />
      Nữ</label>";
	  else
	  echo"<input type='radio' name='phai' id='nam' value='1'/>
      <label for='nam'>Nam 
        <input type='radio' name='phai' id='nu'value='0' checked/>
      Nữ</label>";
      ?>
      </td>
    </tr>
    <tr>
      <td style="padding-left:15px">Địa chỉ</td>
      <td><label for="diachi"></label>
      <textarea name="diachi" cols="30" rows="3" id="diachi"><?php  echo $_POST["diachi"];   ?>
        </textarea></td>
    </tr>
    <tr>
      <td style="padding-left:15px">Ngày sinh</td>
      <td><label for="ngay">Ngày</label>
        <select name="ngay" id="ngay">
        <?php
		for($i = 1; $i <= 31; $i++)
		{
			if($i==date("d"))
			echo "<option selected>$i</option>";
			else
			echo "<option>$i</option>";
		}
		
		?>
        
      </select> <label for="thang">Tháng</label>
      <select name="thang" id="thang">
      <?php
		for($i = 1; $i <= 12; $i++)
		{
			if($i==date("m"))
			echo "<option selected>$i</option>";
			else
			echo "<option>$i</option>";
		}
		
		?>
      </select> <label for="nam2">Năm</label>
      <select name="nam" id="nam2">
      <?php
		for($i = 1970; $i <= 2020; $i++)
		{
			if($i==date("Y"))
			echo "<option selected>$i</option>";
			else
			echo "<option>$i</option>";
		}
		
		?>
      </select></td>
    </tr>
    <tr>
      <td style="padding-left:15px">Điện thoại</td>
      <td><label for="dienthoai"></label>
      <input name="dienthoai" type="text" id="dienthoai" size="40" value="<?php  echo $_POST["dienthoai"];   ?>"/></td>
    </tr>
    <tr>
      <td style="padding-left:15px">Email</td>
      <td><label for="email"></label>
      <input name="email" type="text" id="email" size="40" value="<?php  echo $_POST["email"];   ?>"/></td>
    </tr>
    <tr>
      <td style="padding-left:15px">User</td>
      <td><label for="user"></label>
      <input name="user" type="text" id="user" size="40" value="<?php  echo $_POST["user"];   ?>"/></td>
    </tr>
    <tr>
      <td style="padding-left:15px">Mật khẩu</td>
      <td><label for="matkhau"></label>
      <input name="matkhau" type="password" id="matkhau" size="40" value="<?php  echo $_POST["matkhau"];   ?>"/></td>
    </tr>
    <tr>
      <td style="padding-left:15px">Xác nhận mật khẩu</td>
      <td><label for="xacnhanmatkhau"></label>
      <input name="xacnhanmatkhau" type="password" id="xacnhanmatkhau" size="40" value="<?php  echo $_POST["xacnhanmatkhau"];   ?>"/></td>
    </tr>
    <tr>
      <td height="35" colspan="2" align="center"><input type="submit" name="dk" id="dk" value="Đăng ký" /></td>
    </tr>
  </table>
</form>
</body>
</html>